package za.org.jcicada.syshealth;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;

import javax.swing.AbstractListModel;

import za.org.jcicada.genss.SystemURN;

public class SystemModel extends AbstractListModel {

	private static final long serialVersionUID = 1L;
	private List<SystemURN> urns = new ArrayList<SystemURN>();

	public void setElements(Set<SystemURN> systemURNs) {
		urns = new ArrayList<SystemURN>(systemURNs);
		fireContentsChanged(this, 0, urns.size());
	}
	
	public void addElement(SystemURN systemURN) {
		if (!urns.contains(systemURN)) {
			urns.add(systemURN);
			fireContentsChanged(this, urns.size() - 1, urns.size());
		}
	}
	
	public void removeElement(SystemURN systemURN) {
		int index = urns.indexOf(systemURN);
		urns.remove(systemURN);
		fireContentsChanged(this, index, urns.size());
	}

	public Object getElementAt(int arg0) {
		return urns.get(arg0);
	}

	public int getSize() {
		return urns.size();
	}
	
	public void clear() {
		int previousSize = getSize();
		urns.clear();
		fireIntervalRemoved(this, 0, previousSize);
	}

}
